<?php
require_once 'Xiachufang/entity/RecipeWiki.php';
class WikiLogic {
	/**
	 * 分页获取WIKI的id列表
	 *
	 * @param unknown_type $page
	 * @param unknown_type $pageSize
	 * @return PageResult
	 */
	static function pagedGetWikiIds($page, $pageSize) {
		$table = RecipeWikiEntity::getTable();
		$sql = "select count(*) from ".$table;
		$db = DBMgr::getSlaver($table);
		$total = intval($db->querySingle($sql)); 
		if ($total == 0) return PageResult::build(0, $page, $pageSize, array());
		
		$sql = "select recipe_wiki_id from ".$table." order by recipe_wiki_id desc";
		$data = $db->query($sql)->asArray1();
		return PageResult::build($total, $page, $pageSize, $data);
	}
	
	/**
	 * 获取用户编辑过的菜谱
	 *
	 * @param unknown_type $actorId
	 * @param unknown_type $typeId
	 * @param unknown_type $page
	 * @param unknown_type $pageSize
	 * @return PageResult
	 */
	static function pagedGetActorWikiIds($actorId, $typeId, $page, $pageSize) {
		$table = RecipeWikiEntity::getTable();
		$sql = "select recipe_wiki_id,recipe_id from ".$table." where actor_id=".$actorId." order by recipe_wiki_id desc";
		$db = DBMgr::getSlaver($table);
		return $db->fullPagedQuery($sql, $page, $pageSize);
	}

	/**
	 * 获取对菜谱有贡献的用户Id
	 *
	 * @param unknown_type $recipeId
	 */
	static function getRecipeActorIds($recipeId) {
		$table = RecipeWikiEntity::getTable();
		$sql = "select actor_id,recipe_wiki_id from ".$table." where recipe_id=".$recipeId." order by recipe_wiki_id desc";
		$db = DBMgr::getSlaver($table);
		return $db->query($sql)->asArray();
	}
}
?>